#/*************************************************************************
#    > File Name: examples/example_List.py
#    > Author: Yan Wang
#    > Mail: wangyan@imnu.edu.cn
#    > Created Time: 2022年06月22日 星期三 18时38分06秒
# ************************************************************************/
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.append('./Lib/')
from Load_Lib import * 


print("The examples in this file are:")   
ex_name={"1":"Mapping_DF_to_Sentence"
        ,"2":"Mapping_DictList_to_Sentence"
        ,"3":"Mapping_Dict_to_Sentence"
        ,"4":"Get_Replace_Sentence"
        ,"all":"all examples"}    #字典，所有对应函数为Lib/Value_Calculation.py
for key in ex_name:
    print(key, ex_name[key])       #if条件语句，如果key在ex_name里面，则输出eg：1 Mapping_DF_to_Sentence
num=input("请输入想要运行的例子：")


df_name="Examples/test_input/data_grid_mh_mch.tsv"
df = pd.read_table(df_name)
replaced_content={"tb":"    1 scan1: {} # TB",
        "sba" :"    2 scan1: {} # sinbma",
        "mh"  :"   25 scan1: {} # mh1",
        "mH"  :"   35 scan1: {} # mh2",
        "mA"  :"   36 scan1: {} # mh3",
        "mch" :"   37 scan1: {} # mhc"}
input_value_list=Get_Maplist_Key(replaced_content)   #返回replaced_content所有的key
if num == "1" or num == ex_name["1"] or num == "all":
    # Mapping_DF_to_Sentence
# 三个参数(A,B,C),A为被读取的数据文件,B为被替换的内容,C为替换到B里的内容
# 将df中按照replaced_content的key提取出数据，并替换到replaced_content里， 每一行数据替换一次。
# 最后输出为：一系列被替换的replaced_content  每一组都要替换一次共13组
#  ['    1 scan1: 2.066366e+01 # TB',
#  '    2 scan1: -5.220500e-02 # sinbma',
#  '   25 scan1: 2.893582e+01 # mh1',
#  '   35 scan1: 1.250000e+02 # mh2',
#  '   36 scan1: 8.251534e+01 # mh3',
#  '   37 scan1: 8.557787e+01 # mhc'],
#  ['    1 scan1: 1.043617e+01 # TB',
#  '    2 scan1: -1.000500e-01 # sinbma',
#  '   25 scan1: 2.750694e+01 # mh1',
#  '   35 scan1: 1.250000e+02 # mh2',
#  '   36 scan1: 1.173513e+02 # mh3',
#  '   37 scan1: 9.376629e+01 # mhc'],
#  另外还有11组列表
# 最后一个参数[2,3]代表只提取df中的第2，3行的参数
    Exhibit_Function(Mapping_DF_to_Sentence, [df, input_value_list, replaced_content,[2,3]])


if num == "2" or num == ex_name["2"] or num == "all":
    # Mapping_DictList_to_Sentence
# 四个参数(A,B,C,D),A为被读取的数据文件,B为分组数,C为被替换的内容,D替换到B里的内容
# 同样执行上面的替换,但将所有数据分为node_num组,一共替换node_num次
# 最后输出为：一系列被替换的replaced_content,分成了3组
#  ['    1 scan1: [20.663656, 10.436171, 8.207647999999999, 17.589038000000002, 9.616626] # TB',
#  '    2 scan1: [-0.052204999999999994, -0.10005, -0.123984, -0.058461, -0.106299] # sinbma',
#  '   25 scan1: [28.93582, 27.506943, 20.960417, 25.816828, 23.199866] # mh1',
#  '   35 scan1: [125.0, 125.0, 125.0, 125.0, 125.0] # mh2',
#  '   36 scan1: [82.515336, 117.351299, 90.646077, 82.13599, 85.32181800000001] # mh3',
#  '   37 scan1: [85.57786800000001, 93.766289, 106.37348600000001, 113.014924, 122.66396100000001] # mhc'],
#  另外还有2组列表
    node_num=3
    df_name="Examples/test_input/data_grid_mh_mch.tsv"
    df = pd.read_table(df_name)
    replaced_content={"tb":"    1 scan1: {} # TB",
            "sba" :"    2 scan1: {} # sinbma",
            "mh"  :"   25 scan1: {} # mh1",
            "mH"  :"   35 scan1: {} # mh2",
            "mA"  :"   36 scan1: {} # mh3",
            "mch" :"   37 scan1: {} # mhc"}
    input_dict_list=Make_DictList_from_DF(df, node_num, input_value_list)   #将df分成3组，输出为字典形式的input_value_list
    Exhibit_Function(Mapping_DictList_to_Sentence, [input_dict_list, input_value_list, replaced_content])


if num == "3" or num == ex_name["3"] or num == "all":
    # Mapping_Dict_to_Sentence
# 三个参数(A,B,C),A为输入的字典,B为origin_path_list中所有的key,C为源列表(被替换的)
# 针对每一个key,只替换一次 
# 最后输出为：['PROCESS          : sigh_w4b_1', "RECORD_FILE      : 'tmp/sigh_w4b_2.dat'", "INPUT_FILE       : 'file_3.dat'"] 
    input_path_dict={"process":"{}".format(1),
            "tmp" :"{}".format(2),
            "file":"{}".format(3)}
    origin_path_list={"process":"PROCESS          : sigh_w4b_{}",
            "tmp" :"RECORD_FILE      : 'tmp/sigh_w4b_{}.dat'",
            "file":"INPUT_FILE       : 'file_{}.dat'"}
    input_value_list=Get_Maplist_Key(origin_path_list)
    Exhibit_Function(Mapping_Dict_to_Sentence, [input_path_dict, input_value_list, origin_path_list])


if num == "4" or num == ex_name["4"] or num == "all":
    # Get_Replace_Sentence
# 两个参数(A,B),A为输入的字典,B为源列表(被替换的)
# 整合Mapping函数,生成一个列表，列表的每一项为dict中的一个value做了对应替换后的结果
# 最后输出为：
#  ['PROCESS          : sigh_w4b_1',
#   "RECORD_FILE      : 'tmp/sigh_w4b_2.dat'",
#   "INPUT_FILE       : 'file_3.dat'"]
    Exhibit_Function(Get_Replace_Sentence,[input_path_dict, origin_path_list])
